//
//  ClassifySectionCell.m
//  MyNewProject
//
//  Created by 王春辉 on 2020/1/3.
//  Copyright © 2020年 sun. All rights reserved.
//

#import "ClassifySectionCell.h"


@interface ClassifySectionCell()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@end

@implementation ClassifySectionCell
@synthesize imageView = _imageView;
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.layer.masksToBounds = true;
        self.layer.cornerRadius = 4;
        self.layer.borderColor = SKColorWithHex(0xe1e1e1).CGColor;
        self.layer.borderWidth = 0.38;
        self.backgroundColor = [UIColor whiteColor];
        [self initContentViews];
    }
    return self;
}

- (void)initContentViews {
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.height.mas_equalTo(self.imageView.mas_width);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_offset(-10);
        make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(11);
        make.height.mas_equalTo(13);
        make.bottom.mas_equalTo(self.priceLabel.mas_top).mas_offset(-11);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = SKFONT_Medium(10);
    label.textColor = SKColorWithHex(0xFF3030);
    label.text = @"现价 ¥";
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.bottom.mas_equalTo(self.priceLabel).mas_offset(2);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-11);
        make.left.mas_equalTo(label.mas_right).mas_offset(4);
    }];
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareButton setImage:SKIMAGE_NAMED(@"shop_share_btn_img") forState:UIControlStateNormal];
    [shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:shareButton];
    shareButton.hidden = true;
    
    [shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.titleLabel);
        make.centerY.mas_equalTo(self.priceLabel);
    }];
}

#pragma mark -- mark 懒加载

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithImage:SKIMAGE_NAMED(@"logo")];
        [self addSubview:_imageView];
    }
    return _imageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = SKFONT_BOLD_SIZE(13);
        _titleLabel.textColor = SKColorWithHex(0x333333);
        _titleLabel.text = @" ";
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = SKColorWithHex(0xFF3030);
        _priceLabel.font = SKFONT_BOLD_SIZE(13);
        _priceLabel.text = @" ";
        [self addSubview:_priceLabel];
    }
    return _priceLabel;
}

#pragma mark -- mark 业务逻辑
- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}
- (void)setPrice:(NSString *)price {
    _price = price;
    self.priceLabel.text = [NSString stringWithFormat:@"%@", price];
}

#pragma mark -- mark EVENT

- (void)shareButtonClick:(UIButton *)sender {
    if (self.shareButtonClickBlock) {
        self.shareButtonClickBlock(); }
}
@end
